<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.org/ui"
                template="/WEB-INF/template.xhtml">

    <ui:define name="head">        
        <script type="text/javascript">
            //<![CDATA[
                function handleMessage(facesmessage) {
                    facesmessage.severity = 'info';
                    
                    PF('growl').show([facesmessage]);
                }
            //]]> 
        </script>
    </ui:define>
    
    <ui:define name="title">
        Notify
    </ui:define>

    <ui:define name="description">
        This sample demonstrates how to push FacesMessages to all subscribers.
    </ui:define>

    <ui:define name="implementation">

        <p:growl widgetVar="growl" showDetail="true" />
            
        <h:form>   
            <h:panelGrid columns="2">
                <p:outputLabel for="summary" value="Summary: " /> 
                <p:inputText id="summary" value="#{notifyView.summary}" required="true" />

                <p:outputLabel for="detail" value="Detail: " /> 
                <p:inputText id="detail" value="#{notifyView.detail}" required="true" />
            </h:panelGrid>

            <p:commandButton value="Send" actionListener="#{notifyView.send}" />     
        </h:form>

        <p:socket onMessage="handleMessage" channel="/notify" />
        
    </ui:define>

    <ui:define name="source">
        <p:tabView>
            <p:tab title="notify.xhtml">
                <pre name="code" class="brush:xml">
&lt;p:growl widgetVar="growl" showDetail="true" /&gt;
            
&lt;h:form&gt;
    &lt;h:panelGrid columns="2"&gt;
        &lt;p:outputLabel for="summary" value="Summary: " /&gt; 
        &lt;p:inputText id="summary" value="\#{notifyView.summary}" required="true" /&gt;

        &lt;p:outputLabel for="detail" value="Detail: " /&gt; 
        &lt;p:inputText id="detail" value="\#{notifyView.detail}" required="true" /&gt;
    &lt;/h:panelGrid&gt;

    &lt;p:commandButton value="Send" actionListener="\#{notifyView.send}" /&gt;
&lt;/h:form&gt;

&lt;p:socket onMessage="handleMessage" channel="/notify" /&gt;

&lt;script type="text/javascript"&gt;
        function handleMessage(facesmessage) {
            facesmessage.severity = 'info';

            PF('growl').show([facesmessage]);
        }
&lt;/script&gt;
                </pre>
            </p:tab>

            <p:tab title="NotifyView.java">
                <pre name="code" class="brush:java">
package org.primefaces.showcase.push.notify;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import org.apache.commons.lang.StringEscapeUtils;
import org.primefaces.push.EventBus;
import org.primefaces.push.EventBusFactory;

@ManagedBean
@RequestScoped
public class NotifyView {
    
    private final static String CHANNEL = "/notify";
    
    private String summary;
    
    private String detail;
    
    public String getSummary() {
        return summary;
    }
    public void setSummary(String summary) {
        this.summary = summary;
    }
    
    public String getDetail() {
        return detail;
    }
    public void setDetail(String detail) {
        this.detail = detail;
    }
    
    public void send() {
        EventBus eventBus = EventBusFactory.getDefault().eventBus();
        eventBus.publish(CHANNEL, new FacesMessage(StringEscapeUtils.escapeHtml(summary), StringEscapeUtils.escapeHtml(detail)));
    }
}
                </pre>
            </p:tab>
            
            <p:tab title="NotifyResource.java">
                <pre name="code" class="brush:java">
package org.primefaces.showcase.push.notify;

import javax.faces.application.FacesMessage;
import org.primefaces.push.annotation.OnMessage;
import org.primefaces.push.annotation.PushEndpoint;
import org.primefaces.push.impl.JSONEncoder;

@PushEndpoint("/notify")
public class NotifyResource {
        
    @OnMessage(encoders = {JSONEncoder.class})
    public FacesMessage onMessage(FacesMessage message) {
        return message;
    }

}
                </pre>
            </p:tab>
            
            <p:tab title="Documentation" titleStyleClass="tab-doc docslide-526" />
        </p:tabView>

    </ui:define>

</ui:composition>
